<template>
    <el-container style="min-height: 100vh" >
      <el-aside :width=" sideWith + 'px'" style="background-color: rgb(238, 241, 246);box-shadow: 2px 0 6px rgba(0,21,41,0.35);">

        <Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow" :menus="user.menus"/>

      </el-aside>

      <el-container>
        <el-header style="border-bottom: 1px solid #ccc">

          <Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" :user="user"/>

        </el-header>

        <el-main>

          <router-view @refreshUser="getUser"/>

        </el-main>

      </el-container>
    </el-container>
</template>

<script>
import Aside from "@/components/Aside";
import Header from "@/components/Header";

export default {
  name: 'HomeView',

  data(){
    return {
      collapseBtnClass:'el-icon-s-fold',
      isCollapse:false,
      sideWith:200,
      logoTextShow:true,
      user: {},
    }
  },

  components: {
        Aside,Header
  },

created() {
  this.getUser()
},

  methods:{
    /**
     * 点击按钮触发
     */
    collapse(){
      this.isCollapse = !this.isCollapse
      if(this.isCollapse){
        this.sideWith = 64
        this.collapseBtnClass = 'el-icon-s-unfold'
        this.logoTextShow = false
      }else{
        this.sideWith = 200
        this.collapseBtnClass = 'el-icon-s-fold'
        this.logoTextShow = true
      }
    },

    //从后台获取数据
    getUser(){
      let username = JSON.parse(localStorage.getItem("user")).username ? JSON.parse(localStorage.getItem("user")).username : ""
      this.request.get("/user/username/" + username).then(res =>{
        this.user = res.data
      })
    },


  }
}
</script>

<style>

</style>
